<template>
	<!-- //微信小程序 ：style="[]" 要用数组的形式 -->
	<view class="custom-page-defalut">
		<view class="flex-column" style="justify-content: center;height:inherit">
			<image src="@/static/images/neterr.png" style="width: 400rpx;height: 400rpx;margin:100rpx 0 0;">
			</image>
			<uni-title type="h1" title="网络出了问题" color="#FFFFFF"></uni-title>

			<view class="confirm-button" @tap="checkNetworkState">重新连接网络</view>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from '@/network/apis/auth.js';
	import Local from '@/library/utils/storage.js';
	import {
		getitem
	} from '@/network/apis/user.js';
	export default {
		data() {
			return {
				isTap: false,
			}
		},
		onShow() {
			// #ifdef MP-WEIXIN
			uni.hideHomeButton();
			// #endif
		},
		methods: {
			checkNetworkState() {
				if (this.isTap) return;
				this.isTap = true;
				uni.getNetworkType({
					complete: e => {
						let networkType = e.networkType || 'none';

						if ('none' == networkType) {
							uni.showToast({
								icon: 'none',
								title: '当前无网络，请检查您的网络链接'
							})
							this.isTap = false
						} else {
							// uni.showToast({
							// 	icon: 'none',
							// 	title: '网络已链接'
							// })
							this.Login();// 用登录来测试是否链接
							// uni.reLaunch({
							// 	url:'/pages/index/index'
							// })
						}
						

					}
				});
			},
			
			//检查如果已经登陆过了，每次重启就登录以免过期
			async Login() {
				let account = Local.GetUserAccount();
				let userInfo = Local.GetUserInfo();
				if (account && userInfo) {
					let res = await login(account.userName, account.password);
					if (res.success) {
						if (res.data) {
							Local.SetUserInfo(res.data);
			
							let userdatares = await getitem(res.data.userInfo.id);
							if (userdatares && userdatares.success) {
								if (userdatares.data) {
									Local.SetUserData(userdatares.data);
									uni.navigateBack();
									uni.showToast({
										icon: 'none',
										title: '网络已链接'
									})
								}
			
							} else {
			
							}
						}
					} else {
						console.log(res)
						uni.showToast({
							icon: 'none',
							title: '连接异常'
						})
					}
				}else{
					
				}
				
				this.isTap = false;
			}
		}
	}
</script>

<style scoped>
</style>